package com.cloudkinto.cron;

import com.cloudkinto.service.email.MailSenderService;
import com.cloudkinto.service.order.OrderAmazonService;
import com.cloudkinto.service.order.OrderRakutenService;
import com.cloudkinto.service.order.OrderShopifyService;
import com.cloudkinto.service.order.OrderYahooService;
import com.cloudkinto.service.order.impl.OrderRakutenServiceImpl;
import com.cloudkinto.service.orderoutput.OrderOutputService;
import com.cloudkinto.service.orderqoo.OrderQoo10Service;
import org.apache.commons.collections.list.AbstractLinkedList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.mail.Session;
import javax.mail.Transport;
import java.util.ArrayList;
import java.util.List;

/**
 * @author zhangyy
 * @date 2020/6/18 16:03
 * @description: 定时任务
 */
@ConditionalOnProperty(prefix = "gbc", name = "scheduling", havingValue = "sync")
@Component
public class CronSyncService {
    int round = 0;
    @Autowired
    private OrderRakutenService mRakutenOrderService;
    @Autowired
    private OrderAmazonService mOrderAmzonService;
    @Autowired
    private OrderQoo10Service mOrderQoo10Service;
    @Autowired
    private OrderOutputService mOrderOutService;
    @Autowired
    private OrderShopifyService mShopifyOrderService;
    @Autowired
    private MailSenderService mailSenderService;
    private int current1 = 1;
    private int current2 = 1;
    @Autowired
    private OrderYahooService mYahooService;

    @Scheduled(cron = "0 0/5 * * * ?")
    @Async
    public void confirmRakutenOrder() {
        mRakutenOrderService.autoConfirmOrder();
    }

    @Scheduled(cron = "0 02 6,9,19,20,21 * * ?")
    @Async
    public void autoUploadNoYetExpressNumber() {
        mOrderOutService.autoUploadNoYetExpressNumber();
    }

    @Scheduled(cron = "0 13,43 7-18 * * ?")
    @Async
    public void autoUploadExpressNumber() {
        mOrderOutService.autoUploadLasHourExpressNumber();
    }

    @Scheduled(cron = "0 5/15 * * * ?")
    @Async
    public void refreshRakutenOrder() {
        mRakutenOrderService.autoRefreshOrder();
    }

    @Scheduled(cron = "0 35 * * * ?")
    @Async
    public void refreshRakutenOrder2() {
        mRakutenOrderService.autoRefreshOrder2();
    }

//    @Scheduled(fixedRate = Integer.MAX_VALUE)
//    @Async
//    public void refreshRakutenOrder3() {
//        mRakutenOrderService.autoRefreshOrder3();
//    }


    @Scheduled(cron = "0 15 7-22 * * ?")
    @Async
    public void refreshQoo10Order() {
        mOrderQoo10Service.autoRefreshOrder();
    }

    @Scheduled(cron = "0 18/24 7-22 * * ?")
//    @Scheduled(fixedDelay = Long.MAX_VALUE)
    @Async
    public void refreshYahooOrder() {
        mYahooService.timingSyncYahooOrder("all");
    }


//
//    @Scheduled(cron = "0 15 16-20 * * ?")
//    @Async
//    public void sendRakutenMail1() {
//        try {
//            System.out.println("sendRakutenIntenMail1");
////            mRakutenOrderService.sendInvitationEmail(106L, "2020-09-01", "2021-01-01", "", current1, 500, 2);
//            mRakutenOrderService.sendInvitationEmail(4L, "2022-04-01", "2022-07-01", "", current1, 500, 2);
////            mRakutenOrderService.sendInvitationEmail(28L, "2021-10-04 19:12:14","2021-11-15 07:13:38",  "", current2, 500, 1);
////            mRakutenOrderService.sendInvitationEmail(28L, "2021-03-19 09:20:33","2021-11-15 07:13:38",  "", current2, 500, 2);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        current1 = current1 + 1;
//        current2 = current2 + 1;
//    }
}